/**
 * excel上传记录列表
 */
var pageCurr;
$(function() {
    layui.use('table', function(){
        var table = layui.table
            ,form = layui.form;

        tableIns=table.render({
            elem: '#uploadRecordList'
            ,url:'/uploadRecord/getUploadRecords'
        	,method: 'post' //默认：get请求
            ,cellMinWidth: 80
            ,page: true,
            request: {
                pageName: 'page' //页码的参数名称，默认：page
                ,limitName: 'limit' //每页数据量的参数名，默认：limit
            },response:{
                statusName: 'code' //数据状态的字段名称，默认：code
                ,statusCode: 200 //成功的状态码，默认：0
                ,countName: 'totals' //数据总数的字段名称，默认：count
                ,dataName: 'list' //数据列表的字段名称，默认：data
            }
            ,cols: [[
                {type:'numbers'}
                /*,{field:'id', title:'ID', width:80, unresize: true, sort: true,align:'center',hide:true}*/
                ,{field:'batchNo', width:250, title:'批次号',align:'center'}
                ,{field:'operator', width:100, title:'操作人',align:'center'}
                ,{field:'model', width:150, title: '所属模块',align:'center'}
                ,{field:'ossTypeName', width:150, title: '上传通道',align:'center'}
                ,{field:'total', width:150, title: '总条数',align:'center'}
                ,{field:'failed', width:150, title: '失败条数',align:'center'}
                ,{field:'success', width:150, title: '成功条数',align:'center'}
                ,{field:'isDel', title:'状态',width:150,align:'center',templet:'#isDelTpl'}
                ,{field:'insertTime', width:180, title: '操作时间',align:'center'}
                ,{fixed:'right', title:'文件下载', width:240,align:'center', toolbar:'#optBar'}
            ]]
            ,  done: function(res, curr, count){
            }
        });

        //监听工具条
        table.on('tool(uploadRecordTable)', function(obj){
            var data = obj.data;
            if(obj.event === 'download'){
                //下载错误文件
                uploadRecordErrorDown(data.id);
            }if(obj.event === 'downloadSrc'){
                //下载原始文件
                uploadRecordSrcDown(data.id);
            }
        });

    });
    //搜索框
    layui.use(['form','laydate'], function(){
        var form = layui.form ,layer = layui.layer
            ,laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#qinsertTimeStart'
        });
        laydate.render({
            elem: '#qinsertTimeEnd'
        });
        //TODO 数据校验
        //监听搜索框
        form.on('submit(searchSubmit)', function(data){
            //重新加载table
            load(data);
            return false;
        });
    });
});

function uploadRecordErrorDown(id) {
    //回显数据
    $.get("/uploadRecord/checkErrorUploadFile",{"id":id},function(data){
        if(isLogin(data)){
            if(data.msg!="ok"){
                //弹出错误提示
                layer.alert(data.msg,function () {
                    layer.closeAll();
                });
            }else{
                window.location.href="/uploadRecord/downLoadUploadRecordFile?type=ERROR&id="+id;
            }
        }
    });

}

function uploadRecordSrcDown(id) {
    window.location.href="/uploadRecord/downLoadUploadRecordFile?type=ORIGINAL&id="+id;
}

function load(obj){
    //重新加载table
    tableIns.reload({
        where: obj.field
        , page: {
            curr: pageCurr //从当前页码开始
        }
    });
}


